
var app = getApp();
var until = require("../../../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    url: '',
    images: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  del: function (e) {
    var taht = this
    var zy_id = e.currentTarget.dataset.date
    //查询订单是否已核销
    app.util.request({
      'url': 'entry/wxapp/Selecthxstate',
      data: {
        zy_id: zy_id,
      },
      success: function (res) {
        if (res.data.data.zy_zhenzhuang == 1) {
          wx.showModal({
            title: '温馨提示',
            content: '订单已核销无法取消预约'
          })
        } else {
          app.util.request({
            'url': 'entry/wxapp/Delzjyy',
            data: {
              zy_id: zy_id,
            },
            success: function (res) {
              console.log(res)
              wx.showToast({
                title: '取消成功',
                icon: 'success',
                duration: 2000,
                success: function () {
                  setTimeout(function () {
                    //要延时执行的代码
                    wx.navigateBack({
                      url: '/hyb_yl/mysubpages/pages/wodeyuyue/wodeyuyue'
                    })
                  }, 2000) //延迟时间
                }
              })
            },
          })
        }

      },
    })

  },
  onLoad: function (options) {
    var that = this
    var bgc = wx.getStorageSync('color')
    var yytime = options.yytime
    var str = (yytime).split(" ");
    var str2 = str[1].split("-");
    var str3 = str[0] + " " + str2[1];
    var time = new Date();
    var months = time.getMonth() + 1;
    var seperator11 = "-";
    var seperator22 = ":";
    var strDate = time.getDate();
    var minDate = time.getMinutes();
    if (months >= 1 && months <= 9) {
      months = "0" + months;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
    }
    if (minDate >= 0 && minDate <= 9) {
      minDate = "0" + minDate;
    }
    var currentdates = time.getFullYear() + seperator11 + months + seperator11 + strDate +
      " " + time.getHours() + seperator22 + minDate;
    // return currentdates;
    this.setData({
      times: currentdates
    })
    console.log(currentdates, str3)


    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this
    var id = options.id
    var money = options.money
    app.util.request({
      'url': 'entry/wxapp/Cxhextype',
      data: {
        id: id,
      },
      success: function (res) {
        console.log(res.data)
        var times = until.formatTime(new Date(res.data.data.zy_time * 1000))
        var zy_zhenzhuang = res.data.data.zy_zhenzhuang
        if (zy_zhenzhuang == 1) {
          that.setData({
            title: '订单已完成',
            close: true
          })
          setTimeout(function () {
            that.setData({
              close: false
            })
          }, 2000)
        } else if (currentdates > str3) {
          that.setData({
            title: '订单已逾期,您可以选择删除',
            close: true
          })
          setTimeout(function () {
            that.setData({
              close: false
            })
          }, 2000)
        }
        that.setData({
          cxhextype: res.data.data,

          times: times
        })
      },
    })
    app.util.request({
      'url': 'entry/wxapp/Money',
      'data': {
        id: id,
      },
      success: function (res) {
        console.log(res)
        that.setData({
          detail: res.data.data,
          images: res.data.data.zy_sex
        })
      }
    })
  },
  getstorurl: function () {
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/Scurl',
      success: function (res) {
        console.log(res)
        that.setData({
          url: res.data.data
        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.getstorurl();
    var that = this
    app.util.request({
      'url': 'entry/wxapp/Base',
      success: function (res) {
        that.setData({
          tell: res.data.data.yy_telphone,
        })
      },
      fail: function (err) {
        console.log(err)
      },

    })
  },
  tel: function (e) {
    var that = this;
    var tel = that.data.tell
    //console.log(tel)
    wx.makePhoneCall({
      phoneNumber: tel
    })

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (e) {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})